<template>
	<view class="work-container">
		<!-- 轮播图 -->
		<uni-swiper-dot class="uni-swiper-dot-box" :info="data" :current="current" field="content">
			<swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
				<swiper-item v-for="(item, index) in data" :key="index">
					<view class="swiper-item" @click="clickBannerItem(item)">
						<image :src="item.image" mode="aspectFill" :draggable="false" />
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>
		<view style="margin-left: 3%;">
			<!-- 患者信息 -->
			<uni-section title="患者信息" type="line"></uni-section>
			<uni-row style=" margin-left: 8%;font-size: 17px;">
				<uni-col :span="6">
					<view>姓名:{{name}}</view>
				</uni-col>
				<uni-col :span="5">
					<view>性别:</view>
				</uni-col>
				<uni-col :span="8">
					<view>年龄:</view>
				</uni-col>
			</uni-row>
			<!-- 宫格组件 -->
			<uni-section title="工作站" type="line"></uni-section>
			<view class="grid-body">
				<uni-grid :column="5" :showBorder="false" @change="changeGrid">
					<view v-for="(item, index) in permissions">
						<uni-grid-item :index="1" v-if="item==='病历'||item===1">
							<view class="grid-item-box">
								<uni-icons type="contact" size="30"></uni-icons>
								<text class="text">病历</text>
							</view>
						</uni-grid-item>
						<uni-grid-item :index="2" v-if="item==='医嘱'||item===2">
							<view class="grid-item-box">
								<uni-icons type="staff-filled" size="30"></uni-icons>
								<text class="text">医嘱</text>
							</view>
						</uni-grid-item>
						<uni-grid-item :index="3" v-if="item==='体温单'||item===3">
							<view class="grid-item-box">
								<uni-icons type="heart" size="30"></uni-icons>
								<text class="text">体温单</text>
							</view>
						</uni-grid-item>
						<uni-grid-item :index="4" v-if="item==='诊疗'||item===4">
							<view class="grid-item-box">
								<uni-icons type="personadd" size="30"></uni-icons>
								<text class="text">诊疗</text>
							</view>
						</uni-grid-item>
						<uni-grid-item :index="5" v-if="item==='护理'||item===5">
							<view class="grid-item-box">
								<uni-icons type="personadd-filled" size="30"></uni-icons>
								<text class="text">护理</text>
							</view>
						</uni-grid-item>
					</view>
				</uni-grid>
				<uni-section title="检验检查" type="line"></uni-section>
				<uni-grid :column="5" :showBorder="false" @change="changeGrid">
					<view v-for="(item, index) in permissions">
						<uni-grid-item :index="6" v-if="item==='检验单'||item===6">
							<view class="grid-item-box">
								<uni-icons type="folder-add" size="30"></uni-icons>
								<text class="text">检验单</text>
							</view>
						</uni-grid-item>
						<uni-grid-item :index="7" v-if="item==='检查报告'||item===7">
							<view class="grid-item-box">
								<uni-icons type="folder-add" size="30"></uni-icons>
								<text class="text">检查报告</text>
							</view>
						</uni-grid-item>
					</view>
				</uni-grid>
			</view>
		</view>
		<!-- 扫码组件 -->
		<sl-pda-employ :config="pdaConfig"></sl-pda-employ>
	</view>
</template>

<script>
	import slPdaEmploy, {
		initPdaScan,
		manualTrigScan,
		onUnloadPdaScan,
		BroadcastConfig
	} from '../../uni_modules/sl-pdaEmploy'
	export default {
		components: {
			slPdaEmploy
		},
		data() {
			return {
				name: "",
				pdaConfig: { // 可以抽离出去管理这个配置
					BroadcastAction: 'nantong',
					BroadcastLabelKey: 'data',
					// BroadcastTriglKey: '',
				},
				current: 0,
				swiperDotIndex: 0,
				data: [{
					image: '/static/images/banner/banner01.jpg'
				}],
				permissions:[]
			}
		},
		onLoad() {
			console.log(this.$store.state.user.permissions);
			this.permissions=this.$store.state.user.permissions[0] === '*:*:*' ? [1, 2, 3, 4, 5, 6, 7] : this.$store.state.user.permissions;
			console.log(this.permissions);
			initPdaScan(code => {
				console.log(code)
				this.name = code;
			})
		},
		onUnload() {
			onUnloadPdaScan()
		},
		methods: {
			clickBannerItem(item) {
				console.info(item)
			},
			changeSwiper(e) {
				this.current = e.detail.current
			},
			changeGrid(e) {
				console.log(e.detail.index);
				if (e.detail.index === 3) {
					this.$tab.navigateTo('/pages/nurse/temperature')
				}
			}
		}
	}
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		line-height: inherit;
	}

	/* #endif */

	.text {
		text-align: center;
		font-size: 30rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: -15px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 300rpx;
		line-height: 300rpx;
	}
</style>